package reader.components;

import java.util.Map;

import reader.xml.XMLContext;
import reader.xml.XMLHelper;

import components.AbstractComponent;
import components.Button;

public class ButtonRW extends AbstractComponentRW {

    private static final String TEXT = "text";

    private static final String ACTION = "action";

    public ButtonRW(Map<String, AbstractComponent> opened) {
        super(opened);
    }

    @Override
    public void read(AbstractComponent component, XMLContext context) {
        Button button = (Button) component;
        button.setText(XMLHelper.readStringProperty(context, TEXT));
        button.setAction(XMLHelper.readStringProperty(context, ACTION));
        super.read(component, context);
    }

    @Override
    public void write(AbstractComponent component, XMLContext context) {
        Button button = (Button) component;
        XMLHelper.writeProperty(context, TEXT, button.getText());
        XMLHelper.writeProperty(context, ACTION, button.getAction());
        super.write(component, context);
    }

}
